package org.zqh.mvc.example;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.zqh.mvc.action.Action;
import org.zqh.mvc.annotation.ZqhAction;
import org.zqh.mvc.annotation.ZqhForm;
import org.zqh.mvc.annotation.ZqhResult;
import org.zqh.mvc.annotation.ZqhResults;
import org.zqh.mvc.form.ActionForm;

@ZqhAction(path = "/login")
@ZqhResults(zqhResults = { @ZqhResult(name = "success", path = "success.jsp"),
		@ZqhResult(name = "fail", path = "fail.jsp") })
@ZqhForm(type = "org.zqh.mvc.example.LoginForm")
public class LoginAction implements Action {

	@Override
	public String execute(HttpServletRequest request, ActionForm form,
			Map<String, String> actionForward) {
		LoginForm loginForm = (LoginForm) form;
		request.setAttribute("form", loginForm);

		if (loginForm.getUsername().equals("zqh")
				&& loginForm.getPassword().equals("123"))
			return actionForward.get("success");
		else
			return actionForward.get("fail");
	}

}
